#!/bin/sh

## hyphop ##

#= check and prepare rootfs

LOG(){
    echo "check root: $@" | tee /dev/kmsg
}

LOG "check root fs"

ROOT=
for a in $(cat /proc/cmdline); do
    case $a in
    root=*)
    ROOT=${a#*=}
    ;;
    esac
done


[ "$ROOT" ] || {
    LOG "not root var in"
    exit 1
}

OFF=$(/opt/squashfs_size2 $ROOT 2>/dev/null)
LOG "[i] squash root $ROOT offset + $OFF"

[ "$OFF" ] || {
    LOG "not found squash offset"
    exit 1
}

blkid -pD -O$OFF $ROOT || {
    LOG "not found root blkid"

    LO=$(losetup --show -f -o$OFF $ROOT)
    [ "$LO" ] && {
	LOG "make ext4 overlay $LO"
	mkfs.ext4 -Loverlay $LO
	losetup -d $LO
    }

    sleep 1

}


